﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Drawing;

namespace PizzaLunch
{
    class LogoConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Image img;
            switch (value.ToString().ToUpper())
            {
                case "TX":
                    img = (Image)Resource.ResourceManager.GetObject("Resource/TX16x16.png");
                    break;
                case "SINA":
                default:
                    img = (Image)Resource.ResourceManager.GetObject("Resource/Sina16x16.png");
                    break;
            }
            return img;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Image img = (Image)value;
            string name;
            if (img == (Image)Resource.ResourceManager.GetObject("Resource/TX16x16.png"))
                name = "TX";
            else
                name = "Sina";
            return name;
        }
    }

    class DateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string str;
            DateTime dt = (DateTime)value;
            str = dt.ToString("F");
            return str;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string name = (string)value;
            return Util.ConverDateTime(name);
        }
    }

    class BoolToVisibility : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool bVisible = (bool)value;
            System.Windows.Visibility v;
            if (bVisible)
                v = System.Windows.Visibility.Visible;
            else
                v = System.Windows.Visibility.Collapsed;
            return v;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            System.Windows.Visibility v = (System.Windows.Visibility)value;
            if (v == System.Windows.Visibility.Visible)
                return true;
            return false;
        }
    }
}
